# -*- coding: utf-8 -*-
# @Time : 2021/2/3 14:23
# @Author : shx
# @Email : 925126486@qq.com
# @File : add_co_page.py
# @Project : test
from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select
class AddCoPage(BasePage):
    url_ = 'http://192.168.1.49/crm3/index.php?m=contract&a=add'
    time_locator = (By.ID,'due_time')
    iframe_locator = (By.XPATH,'/html/body/div[9]/iframe')
    tday_locator = (By.ID,'dpTodayInput')
    sj_locator = (By.ID,'business_name')
    tbody_locator = (By.ID,'data')
    tr_locator = (By.TAG_NAME, 'tr')
    td_locator = (By.TAG_NAME, 'td')
    business_locator = (By.CSS_SELECTOR,'input[name=business]')
    span_locator = (By.XPATH,'/html/body/div[7]/div[3]/div/'
                                          'button[1]/span')
    price_locator = (By.ID,'price')
    start_date_locator = (By.ID,'start_date')
    dpTitle_locator = (By.XPATH,'//*[@id="dpTitle"]/div[6]/a')
    determine_locator = (By.XPATH,'/html/body/div/div[3]/table/tbody/tr[2]/td[3]')
    end_date_locator = (By.ID,'end_date')
    determ_locator = (By.XPATH,'/html/body/div/div[3]/table/tbody/tr[3]/td[4]')
    frame_locator = (By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tbody/tr[7]/td[2]/div/div[2]/iframe')
    body_locator = (By.CSS_SELECTOR,'body')
    input_locator = (By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]')


    def signing_time(self):
        """点击日期框"""
        self.find_element(self.time_locator).click()

    def select_time(self):
        """选择当天"""
        self.driver.switch_to.frame(self.find_element(self.iframe_locator))  # 切换到日期页面
        self.find_element(self.tday_locator).click()

    def point_sj(self):
        """点击商机框"""
        self.find_element(self.sj_locator).click()

    def select_sjj(self,business_name):
        """选择商机"""
        tbody = self.find_element(self.tbody_locator)
        trs = tbody.find_elements(*self.tr_locator)
        for tr in trs:
            tds = tr.find_elements(*self.td_locator)
            if tds[1].text == business_name:
                tds[0].find_element(*self.business_locator).click()
                self.find_element(self.span_locator).click()
                break

    def fill_price(self,price):
        """填写合同金额"""
        self.find_element(self.price_locator).send_keys(price)

    def point_start_time(self):
        """点击生效时间框"""
        self.find_element(self.start_date_locator).click()

    def select_start_time(self):
        """选择合同生效时间"""
        self.driver.switch_to.frame(self.find_element(self.iframe_locator))
        self.find_element(self.dpTitle_locator).click()

    def sure_start_time(self):
        """点击生效时间确定"""
        self.find_element(self.determine_locator).click()

    def point_end_time(self):
        """点击到期时间框"""
        self.find_element(self.end_date_locator).click()

    def select_end_time(self):
        """选择合同到期时间"""
        self.driver.switch_to.frame(self.find_element(self.iframe_locator))
        self.find_element(self.dpTitle_locator).click()

    def sure_end_time(self):
        """点击到期时间确定"""
        self.find_element(self.determ_locator).click()

    def input_content(self,content):
        """填写条件和条款内容"""
        self.driver.switch_to.frame(self.find_element(self.frame_locator))
        self.find_element(self.body_locator).send_keys(content)

    def dianji(self):
        """点击添加合同"""
        self.driver.switch_to.parent_frame()
        self.find_element(self.input_locator).click()
